--[[ AQ.lua
********************************
*                                                            *
* The LUA++ Scripting Project        *
*                                                            *
********************************

This software is provided as free and open source by the
staff of The LUA++ Scripting Project, in accordance with 
the AGPL license. This means we provide the software we have 
created freely and it has been thoroughly tested to work for 
the developers, but NO GUARANTEE is made it will work for you 
as well. Please give credit where credit is due, if modifying,
redistributing and/or using this software. Thank you.

~~End of License Agreement
-- LUA++ staff, March 26, 2008. ]]

--Anubisath Defender by Project eXa
function Defender_ExplodeTwo(pUnit, event) --Fix for broken spell.
	pUnit:CastSpell(25699)
end

function Defender_Explode(pUnit, Event)
	if pUnit:GetHealthPct() < 10 then
		pUnit:RemoveEvents()
		pUnit:FullCastSpell(25698)
		pUnit:StopMovement(7100)
		pUnit:RegisterEvent("Defender_ExplodeTwo", 7000, 1)
	end
end

function Defender_Enrage(pUnit, Event)
	if pUnit:GetHealthPct() < 10 then
		pUnit:CastSpell(44779)
		pUnit:RemoveEvents()
	end
end

function Defender_Thunderclap(pUnit, Event)
	pUnit:CastSpell(2834)
	pUnit:RegisterEvent("Defender_Thunderclap2",math.random(45000,65000),1)
end

function Defender_Thunderclap2(pUnit, Event)
	pUnit:CastSpell(2834)
	pUnit:RegisterEvent("Defender_Thunderclap",math.random(45000,65000),1)
end

function Defender_ShadowStorm(pUnit, Event)
	pUnit:CastSpell(2148)
	pUnit:RegisterEvent("Defender_ShadowStorm2",math.random(45000,65000),1)
end

function Defender_ShadowStorm2(pUnit, Event)
	pUnit:CastSpell(2148)
	pUnit:RegisterEvent("Defender_ShadowStorm",math.random(45000,65000),1)
end

function Defender_Plague(pUnit, Event) --No extreme issues here so I won't comment it out. It is supposed to affect players within 5yards of the affected player, this can be fixed. Please do so by checking the distance from the affected players to nearby players, if it's less than 5yards have the boss cast the spell on them.
	pUnit:CastSpellOnTarget(22997, pUnit:GetRandomPlayer(0))
	pUnit:RegisterEvent("Defender_Plague2",math.random(45000,65000),1)
end

function Defender_Plague2(pUnit, Event) --No extreme issues here so I won't comment it out. It is supposed to affect players within 5yards of the affected player, this can be fixed. Please do so by checking the distance from the affected players to nearby players, if it's less than 5yards have the boss cast the spell on them.
	pUnit:CastSpellOnTarget(22997, pUnit:GetRandomPlayer(0))
	pUnit:RegisterEvent("Defender_Plague",math.random(45000,65000),1)
end

function Defender_OnCombat(pUnit, Event) --We don't need variables here because there are only 2 options to choose from, therefore we can use the else statement.
	if math.random(1, 2) == 1 then
		pUnit:RegisterEvent("Defender_Plague",math.random(45000,65000),1)
	end
	if math.random(1, 2) == 1 then
		pUnit:RegisterEvent("Defender_ShadowStorm",math.random(45000,65000),1)
	else
		pUnit:RegisterEvent("Defender_Thunderclap",math.random(45000,65000),1)
	end
	if math.random(1, 2) == 1 then
		pUnit:RegisterEvent("Defender_Enrage",1000,0)
	else
		pUnit:RegisterEvent("Defender_Explode",1000,0)
	end
	if math.random(1, 2) == 1 then
		pUnit:CastSpell(13022)
	else
		pUnit:CastSpell(19595)
	end
end

function Defender_OnLeaveCombat(pUnit)
	pUnit:RemoveEvents()
end

RegisterUnitEvent(15277, 1, "Defender_OnCombat")
RegisterUnitEvent(15277, 2, "Defender_OnLeaveCombat")


--Anubisath Sentinel by Project eXa

function Sentinel_OnCombat(Unit, event)
	local CoinFlip=math.random(1,9)
	if CoinFlip==1 then
		Unit:CastSpell(28747)
		Mending = nil
	elseif CoinFlip==2 then
		Unit:CastSpell(21737)
		KnockAway = nil
	elseif CoinFlip==3 then
		Unit:CastSpell(25777)
		Thorns = nil
	elseif CoinFlip==4 then
		Unit:CastSpell(2834)
		ThunderClap = nil
	elseif CoinFlip==5 then
		Unit:CastSpell(13022)
		ReflectArcFire = nil
	elseif CoinFlip==6 then
		Unit:CastSpell(19595)
		ReflectShadFrost = nil
	elseif CoinFlip==7 then
		Unit:CastSpell(2148)
		ShadowStorm = nil
	elseif CoinFlip==8 then
		Unit:CastSpell(812)
		ManaBurn = nil
	elseif CoinFlip==9 then
		Unit:CastSpell(9347)
		MortalStrike = nil
	end
	Unit:RegisterEvent("DeathCheck",1000,0)
end

function DeathCheck(Unit, event)
	if Mending==true then
		Unit:CastSpell(28747)
		Mending = nil
		MaxHp = Unit:GetMaxHealth()
		SetHp = Unit:GetHealth() + (MaxHp / 2)
		Unit:SetHealth(SetHp)
	elseif KnockAway==nil then
		Unit:CastSpell(21737)
		KnockAway = true
		MaxHp = Unit:GetMaxHealth()
		SetHp = Unit:GetHealth() + (MaxHp / 2)
		Unit:SetHealth(SetHp)
	elseif Thorns==nil then
		Unit:CastSpel(25777)
		Thorns = true
		MaxHp = Unit:GetMaxHealth()
		SetHp = Unit:GetHealth() + (MaxHp / 2)
		Unit:SetHealth(SetHp)
	elseif ThunderClap==nil then
		Unit:CastSpell(2834)
		ThunderClap = true
		MaxHp = Unit:GetMaxHealth()
		SetHp = Unit:GetHealth() + (MaxHp / 2)
		Unit:SetHealth(SetHp)
	elseif ReflectArcFire==nil then
		Unit:CastSpell(13022)
		ReflectArcFire = true
		MaxHp = Unit:GetMaxHealth()
		SetHp = Unit:GetHealth() + (MaxHp / 2)
		Unit:SetHealth(SetHp)
	elseif ReflectShadFrost==nil then
		Unit:CastSpell(19595)
		ReflectShadFrost = true
		MaxHp = Unit:GetMaxHealth()
		SetHp = Unit:GetHealth() + (MaxHp / 2)
		Unit:SetHealth(SetHp)
	elseif ShadowStorm==nil then
		Unit:CastSpell(2148)
		ShadowStorm = true
		MaxHp = Unit:GetMaxHealth()
		SetHp = Unit:GetHealth() + (MaxHp / 2)
		Unit:SetHealth(SetHp)
	elseif ManaBurn==nil then
		Unit:CastSpell(812)
		ManaBurn = true
		MaxHp = Unit:GetMaxHealth()
		SetHp = Unit:GetHealth() + (MaxHp / 2)
		Unit:SetHealth(SetHp)
	elseif MortalStrike==nil then
		Unit:CastSpell(9347)
		MortalStrike = true
		MaxHp = Unit:GetMaxHealth()
		SetHp = Unit:GetHealth() + (MaxHp / 2)
		Unit:SetHealth(SetHp)
	end
end

function Sentinel_OnDeath(Unit, event)
	if Mending==true then
		Mending = nil
	elseif KnockAway==true then
		KnockAway = nil
	elseif Thorns==true then
		Thorns = nil
	elseif ThunderClap==true then
		ThunderClap = nil
	elseif ReflectArcFire==true then
		ReflectArcFire = nil
	elseif ReflectShadFrost==true then
		ReflectShadFrost = nil
	elseif ShadowStorm==true then
		ShadowStorm = nil
	elseif ManaBurn==true then
		ManaBurn = nil
	elseif MortalStrike==true then
		MortalStrike = nil
	end
	Unit:RemoveEvents()
end

function Sentinel_OnLeaveCombat(Unit)
	Unit:RemoveEvents()
end

RegisterUnitEvent(15264,1,"Sentinel_OnCombat")
RegisterUnitEvent(15264,2,"Sentinel_OnLeaveCombat")
RegisterUnitEvent(15264,4,"Sentinel_OnDeath")

--Anubisath Warder by Project eXa
function Warder_Root(Unit, event)
	Unit:CastSpell(20699)
	Unit:RegisterEvent("Warder_Root2",math.random(15000,30000),1)
end

function Warder_Root2(Unit, event)
	Unit:CastSpell(20699)
	Unit:RegisterEvent("Warder_Root",math.random(15000,30000),1)
end

function Warder_Fear(Unit, event)
	Unit:CastSpell(30584)
	Unit:RegisterEvent("Warder_Fear2",math.random(15000,30000),1)
end

function Warder_Fear2(Unit, event)
	Unit:CastSpell(30584)
	Unit:RegisterEvent("Warder_Fear",math.random(15000,30000),1)
end

function Warder_Cloud(Unit, event)
	Unit:FullCastSpell(26072)
	Unit:RegisterEvent("Warder_Cloud2",math.random(12000,25000),1)
end

function Warder_Cloud2(Unit, event)
	Unit:FullCastSpell(26072)
	Unit:RegisterEvent("Warder_Cloud",math.random(12000,25000),1)
end

function Warder_Silence(Unit, event)
	Unit:FullCastSpell(12528)
	Unit:RegisterEvent("Warder_Silence2",math.random(12000,25000),1)
end

function Warder_Silence2(Unit, event)
	Unit:FullCastSpell(12528)
	Unit:RegisterEvent("Warder_Silence",math.random(12000,25000),1)
end

function Warder_Nova(Unit, event)
	Unit:CastSpell(18432)
	Unit:RegisterEvent("Warder_Nova2",math.random(25000,45000),1)
end

function Warder_Nova2(Unit, event)
	Unit:CastSpell(18432)
	Unit:RegisterEvent("Warder_Nova",math.random(25000,45000),1)
end

function Warder_OnCombat(Unit, event)
	if math.random(1,2)==1 then
		Unit:CastSpell(20699)
		Unit:RegisterEvent("Warder_Root",math.random(15000,30000),1)
	else
		Unit:CastSpell(30584)
		Unit:RegisterEvent("Warder_Fear",math.random(15000,30000),1)
	end
	if math.random(1,2)==1 then
		Unit:FullCastSpell(26072)
		Unit:RegisterEvent("Warder_Cloud",math.random(12000,25000),1)
	else
		Unit:FullCastSpell(12528)
		Unit:RegisterEvent("Warder_Silence",math.random(12000,25000),1)
	end
	Unit:RegisterEvent("Warder_Nova",math.random(25000,45000),1)
end

function Warder_OnLeaveCombat(Unit)
     Unit:RemoveEvents()
end


RegisterUnitEvent(15311,1,"Warder_OnCombat")
RegisterUnitEvent(15311,2,"Warder_OnLeaveCombat")



--Obsidian Nullifier by Project eXa
function Nullifier_ShockBlast(pUnit, event)
	if pUnit:GetManaPct() > 99 then
		pUnit:CastSpell(26458)
		pUnit:SetMana(0)
	end
end

function Nullifier_Siphon(pUnit, event) --Not blizzlike but it will work until I can get a better idea.
	if pUnit:GetManaPct() > 89 then
		pUnit:FullCastSpell(27287)
		pUnit:SetMana(pUnit:GetMana() + pUnit:GetMana()) --I know it will go over 100% mana, but it's okay cause it get's reset to 0. Plus this prevents glitches.
	else
		pUnit:FullCastSpell(27287)
		pUnit:SetMana(pUnit:GetMana() + (pUnit:GetMaxHealth() /(10)))
	end
end

function Nullifier_OnCombat(Unit, event) --There isnt a :SetManaPct() function.
	Unit:SetMana(0)
	Unit:SetMaxMana(50000)
	Unit:RegisterEvent("Nullifier_Siphon",2000,0)
	Unit:RegisterEvent("Nullifier_ShockBlast",1000,0)
end

function Nullifier_OnLeaveCombat(Unit)
	Unit:RemoveEvents()
end


RegisterUnitEvent(15312,1,"Nullifier_OnCombat")
RegisterUnitEvent(15312,2,"Nullifier_OnLeaveCombat")


--Obsidian Eradicator by Project eXa 
function Eradicator_Siphon(pUnit, event) --Not blizzlike but it will work until I can get a better idea.
	if pUnit:GetManaPct() > 89 then
		pUnit:FullCastSpell(27287)
		pUnit:SetMana(pUnit:GetMana() + pUnit:GetMana())  --I know it will go over 100% mana, but it's okay cause it get's reset to 0. Plus this prevents glitches.
	else
		pUnit:FullCastSpell(27287)
		pUnit:SetMana(pUnit:GetMana() + (pUnit:GetMaxHealth() /(10)))
	end
end

function Eradicator_ShockBlast(pUnit, event)
	if pUnit:GetManaPct() > 99 then
		pUnit:CastSpell(26458)
		pUnit:SetMana(0)
	end
end

function Eradicator_OnCombat(Unit, event) --There isnt a :SetManaPct() function.
	Unit:SetMana(0)
	Unit:SetMaxMana(24000)
	Unit:RegisterEvent("Eradicator_Siphon",2000,0)
	Unit:RegisterEvent("Eradicator_ShockBlast",1000,0)
end

function Eradicator_OnLeaveCombat(Unit)
	Unit:RemoveEvents()
end

function Eradicator_OnDied(Unit)
	Unit:SpawnGameObject(181068,Unit:GetX(),Unit:GetY(),Unit:GetZ(),Unit:GetO(),300000)
end

RegisterUnitEvent(15262,1,"Eradicator_OnCombat")
RegisterUnitEvent(15262,2,"Eradicator_OnLeaveCombat")
RegisterUnitEvent(15262,4,"Eradicator_OnDied")


--Qiraji Champion by Ikillonyxia. Couldnt find correct hp% for enrage so didnt include that, along with the nature dot which no info is available for.
function Champion_Cleave(pUnit, event)
     print "Champion_Cleave initiated..."
     pUnit:FullCastSpellOnTarget(31043, pUnit:GetMainTank())
end

function Champion_Fear(pUnit, event)
     print "Champion_Fear initiated..."
     pUnit:FullCastSpell(19134)
end

function Champion_OnEnterCombat(pUnit, event)
     print "Champion_Aggro initiated..."
     pUnit:RegisterEvent("Champion_Cleave", 15000, 0)
     pUnit:RegisterEvent("Champion_Fear", 27000, 0)
end

RegisterUnitEvent(15252, 1, "Champion_OnEnterCombat")

function Champion_OnWipe(pUnit, event)
     pUnit:RemoveEvents()
end

RegisterUnitEvent(15252, 2, "Champion_OnWipe")


--Qiraji Brainwasher by Ikillonyxia. Only spell that I can guess on is the Mind Flay, the rest of his spells are to technical to be making guesses on.

function Brainwasher_MindFlay(pUnit, event) --No info on who it targets, so going to do random target(seems logical).
     print "BrainWasher_MindFlay initiated..."
     pUnit:FullCastSpellOnTarget(26044, pUnit:GetRandomPlayer(0))
end

function Brainwasher_OnEnterCombat(pUnit, event)
     print "Brainwasher_Aggro initiated..."
     pUnit:RegisterEvent("Brainwasher_MindFlay", 32000, 0)
end

RegisterUnitEvent(15247, 1, "Brainwasher_OnEnterCombat")

function Brainwasher_OnWipe(pUnit, event)
     pUnit:RemoveEvents()
end

RegisterUnitEvent(15247, 2, "Brainwasher_OnWipe")


--Qiraji Mindslayer by Ikillonyxia.
function Mindslayer_CleaveRepeat(pUnit, event)
     print "Mindslayer_Cleave initiated..."
     pUnit:FullCastSpellOnTarget(31043, pUnit:GetMainTank())
     pUnit:RegisterEvent("Mindslayer_Cleave", math.random(15000, 18000), 1)
end

function Mindslayer_Cleave(pUnit, event)
     print "Mindslayer_Cleave initiated..."
     pUnit:FullCastSpellOnTarget(31043, pUnit:GetMainTank())
     pUnit:RegisterEvent("Mindslayer_CleaveRepeat", math.random(15000, 18000), 1)
end

function Mindslayer_MindFlay(pUnit, event)
     print "Mindslayer_MindFlay initiated..."
     pUnit:FullCastSpellOnTarget(26044, pUnit:GetRandomPlayer(0))
end

function Mindslayer_OnEnterCombat(pUnit, event)
     print "Mindslayer_Aggro initiated..."
     pUnit:RegisterEvent("Mindslayer_Cleave", math.random(15000, 18000), 1)
     pUnit:RegisterEvent("Mindslayer_MindFlay", 32000, 0)
end

RegisterUnitEvent(15246, 1, "Mindslayer_OnEnterCombat")

function Mindslayer_OnWipe(pUnit, event)
     pUnit:RemoveEvents()
end

RegisterUnitEvent(15246, 2, "Mindslayer_OnWipe")


--::BOSSESS:--


--[[Twin Emperors by Project eXa

--::Emperor Vek'nilash: Swings a big sword, immune to all magical damage (except holy)::--
--Uppercut(18072) - Knocks back a single random target in melee range. 
--Unbalancing Strike(26613) - Inflicts 350% weapon damage and leaves the target unbalanced, reducing their defense skill by 100 for 6 sec. 
--Mutate Bug - Mutates a bug every 10-15 sec or so making it grow to a gigantic size and attack the raid. 

--::Emperor Vek'lor: Caster, immune to all physical damage, has a mana bar.::--
--Shadow Bolt - Spams on his aggro target, hits for 3000-4000. Partially resistible. 
--Blizzard - Slows and damages everyone within its area of effect. 1500 damage/tick. 
--Arcane Burst - 4000-4950 arcane damage AoE counterattack whenever a player is within melee range.
--Explode Bug - Every 7-10 secs Emperor Vek'lor forces a nearby bug to explode, blowing it up

--::Both Emperors::-- 
--Heal Brother - Whenever the twins get within 60 yards of one another, they will spam heal each other.
--Twin Teleport - the two twins will switch places. The twins will be rooted for 2 seconds. There is a complete aggro wipe.
--Berserk(45078) - After 15 minutes, the Emperors will go berserk dramatically increasing damage and wiping the raid.
--Combined Health - The Emperors share health. Damage to one emperor hurts the other emperor as well.

--===SPELLS===--

function Brothers_Berserk(Unit)
Unit:CastSpell(45078)
end

function Veknilash_Uppercut(pUnit, event)
pUnit:CastSpellOnTarget(18072, pUnit:GetRandomPlayer(1))
end

function Veknilash_Unbalancing(pUnit, event)
pUnit:CastSpellOnTarget(26613, pUnit:GetMainTank())
end


function Veknilash_OnCombat(Unit, event)
Veknilash=Unit
--Define Boss as a Unit, set max health to 2 mil and set first NewHp for shared hp calculations
Unit:SetMaxHealth(2000000)
NNewHp=2000000
--Start the registers
Veknilash:RegisterEvent("SharedHealth",1500,0)
Veknilash:RegisterEvent("Brothers_Berserk",900000,0)
Unit:SendChatMessage(11,0,"At least we're getting in combat")
end

function Veklor_OnCombat(Unit, event)
Veklor=Unit
--Define Boss as a Unit, set max health to 2 mil and set first NewHp for shared hp calculations
Unit:SetMaxHealth(20000000)
LNewHp=2000000
--Start the registers
Veklor:RegisterEvent("SharedHealth",1000,0)
Veklor:RegisterEvent("Brothers_Berserk",900000,0)
end

function SharedHealth(Unit, event)
--Get each of their health
NilashHealth = Veknilash:GetHealth()
LorHealth = Veklor:GetHealth()
Veklor:SendChatMessage(11,0,LorHealth)
--Figure out how much Dmg was taken since last check.
NDmgTaken = NNewHp - NilashHealth
LDmgTaken = LNewHp - LorHealth
Veklor:SendChatMessage(11,0,NDmgTaken)
--Share the Dmg between the brothers
NNewHp = NilashHealth - LDmgTaken
LNewHp = LorHealth - NDmgTaken
Veklinash:SendChatMessage(11,0,NNewHp)
--Set the health
Veknilash:SetHealth(NNewHp)
Veklor:SetHealth(LNewHp)
end


RegisterUnitEvent(15275,1,"Veknilash_OnCombat")
RegisterUnitEvent(15276,1,"Veklor_OnCombat") ]]

